<?php

use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
use Illuminate\Support\Facades\DB;

class CreateAddressTable extends Migration
{
    private $tableName = 'address';
    private $tableComment = '地址列表';
    private $primaryKey = 'id';

    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create($this->tableName, function (Blueprint $table) {
            $table->increments(env('DB_CONNECTION') == 'oracle' ? strtoupper($this->primaryKey) : $this->primaryKey)->comment('评论id');
            $table->string('province', 100)->comment('省')->nullable();
            $table->string('province_code', 100)->comment('省编码')->nullable();
            $table->string('city', 100)->comment('市')->nullable();
            $table->string('city_code', 100)->comment('市编码')->nullable();
            $table->string('county', 100)->comment('县城')->nullable();
            $table->string('county_code', 100)->comment('县城编码')->nullable();
            $table->string('address', 300)->comment('详细地址')->nullable();
            $table->string('username', 100)->comment('联系人')->nullable();
            $table->string('phone', 500)->comment('手机号')->nullable();
            $table->unsignedTinyInteger('uid')->comment('用户id')->default(0);
            $table->unsignedTinyInteger('type')->comment('是否默认地址：1是2否')->default(2);;
            $table->timestamps();
            if (env('DB_CONNECTION') == 'oracle') {
                $table->comment = $this->tableComment;
            }
        });

        if (env('DB_CONNECTION') == 'mysql') {
            DB::statement("ALTER TABLE `" . DB::getTablePrefix() . $this->tableName . "` comment '{$this->tableComment}'");
        }
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists($this->tableName);
        if (env('DB_CONNECTION') == 'oracle') {
            $sequence = DB::getSequence();
            $sequence->drop(strtoupper($this->tableName . '_comment_id_SEQ'));
        }
    }
}

